<template>
  <view class="container">
    <view class="bg-user">
      <view class="userinfo flex items-center" v-if="userInfo">
          <up-avatar class="avatar" :src="userInfo.head_img"></up-avatar>
          <view class="info flex-1 ml-[30rpx] text-[white]">
              <view class="nickname" >{{ userInfo.store_name || '' }}</view>
              <view class="flex">
                <view class="mid">门店ID: {{ userInfo.store_id }}</view>
                <up-copy class="mid pl-[10px]" :content="userInfo.username">登陆账号: {{ userInfo.username }}</up-copy>
              </view>
          </view>
      </view>
    </view>
    <view class="menu">
      <up-cell icon="lock" title="修改密码" isLink @click="handleNavigate('/addon/htscrm/pages/admin/edit-password')"></up-cell>
      <up-cell v-if="!userInfo.is_super_admin" icon="reload" title="返回主账号" isLink @click="handleChange()"></up-cell>
      <up-cell title="退出登录" icon="close-circle" isLink @click="handleLogout()"></up-cell>
    </view>
    <f-tabbar :current="3"></f-tabbar>
  </view>
</template>
<script lang="ts" setup>
import FTabbar from '@/addon/htscrm/components/f-tabbar/index.vue'
import { redirect } from '@/utils/common';
import { handleError, ref } from 'vue';
import useAdminStore from '@/addon/htscrm/stores/admin';
import { removeAdminToken } from '../../utils/storage';
const adminStore = useAdminStore()
const userInfo = ref(adminStore.getUserInfo())

function handleNavigate(url: string) {
  redirect({
    url
  })

}

function handleChange() {
  const oldToken = uni.getStorageSync('old_admin_token')
  const oldUserInfo = uni.getStorageSync('old_admin_userinfo')
  adminStore.setAdminToken(oldToken)
  adminStore.setUserInfo(oldUserInfo)
  uni.showToast({title:'登录成功',icon:"none"})
  redirect({
    url:"/addon/htscrm/pages/admin/index",
    mode: 'redirectTo'
  })
}

function handleLogout() {
  // 清空缓存
  removeAdminToken()
  // 去登录
  redirect({
    url:"/addon/htscrm/pages/admin/login",
    mode: 'redirectTo'
  })
}
</script>
<style lang="scss" scoped>
.container {
  background: #f7f7f7;
  min-height: 100vh;
}
.bg-user {
    position: relative;
    width: 100%;
    left: 0;
    top: 0px;
    background: url('https://static.fastht.com/h5_store/user_bg.png') no-repeat ;
	background-size: 100% 100%;
    height: 200rpx;
    /* box-sizing: content-box; */
    z-index: 1; 
}

.userinfo {
    display: flex;
    padding: 50rpx 0 0 60rpx;
}

.userInfo .avatar {
    width: 108rpx;
    height: 108rpx;
    border-radius: 10rpx;
    overflow: hidden;
    background-color: #f8f8f8;
}

.userInfo .avatar image {
    width: 100%;
    height: 100%;
}

.userInfo .info {
    display: flex;
    flex-direction: column;
}

.userInfo .info .nickname {
    font-size: 30rpx;
    font-weight: bold;
    color: #fff;
}

.userInfo .info .mid {
    font-size: 24rpx;
    color: #fff;
    line-height: 36rpx;
}

.userInfo .info .phone {
    color: #fff;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 4rpx 8rpx 4rpx 4rpx;
    height: 36rpx;
    border-radius: 6rpx;
    display: flex;
    align-items: center;
}

.userInfo .info .phone image {
    width: 28rpx;
    height: 28rpx;
}

.userInfo .info .phone text {
    font-size: 22rpx;
}

.menu {
    background: #fff;
    border-radius: 20rpx;
    margin: 0 30rpx;
    margin-top: 30rpx;

    ::v-deep .u-cell:last-child .u-line {
      display: none;
    }
}
</style>